/**
 * Created by Scott on 2017/3/30.
 */
import React from 'react';
import { TreeSelect } from 'antd';
import $ from 'jquery';

export default class MenuTreeSelector extends React.Component {

    componentWillMount () {
        const self = this;
        $.ajax({
            type: "GET",
            url: "/api/SysMenu/findAll",
            contentType: "application/json;charset=utf-8"
        }).then(function ( result ) {
            self.setState({menus: result});
        });
    }
    constructor ( props ) {
        super(props);
        this.state = {
            selectValue: this.props.initValue,
            menus:[]
        };
        this.onChange = this.onChange.bind(this);
    }

    onChange ( value ) {
        this.setState({selectValue: value});
        this.props.onSelect(value);
    }

    render () {
        return (
            <TreeSelect
                style={{ width: 300 }}
                value={this.state.selectValue}
                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                treeData={this.state.menus}
                placeholder="请选择父菜单"
                treeDefaultExpandAll
                onChange={this.onChange}
            />
        );
    }
}